<?php if (!defined("_ECRIRE_INC_VERSION")) return; if (class_exists('PdkMailSender')) return;
/**
 * SPIP Plugin Development Kit
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage pdk
 * @category   outils
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/Developmet-Kit
 * @version    1.0.0
 */

include_spip('classes/pdk_model');
/** 
 *  This is mail sender based on simple mail function
 *
 *  @author Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 */
class PdkMailSender {
    /**
     *  Sends message via simple mail function
     *  @param array or string $email_to Array of emails, or single email
     *  @param string $subject
     *  @param string $message
     *  @param array $options Array of additional parameters: 
     *               from_name - Sender name 
     *               from_email - Sender email
     */
    public function Send($email_to, $subject, $message, $options = array()) {
        if (!is_array($email_to) && $email_to)
            $email_to = array($email_to);
        if (!is_array($email_to) || !$email_to) 
            return false;
        
        $from_name = $options['from_name'] ? $options['from_name'] : '';
        $from_email = $options['from_email'] ? $options['from_email'] : '';
        
        $subject = "=?UTF-8?B?" . base64_encode($subject)."?=";
        $name_from = "=?UTF-8?B?" . base64_encode($from_name)."?=";
        
        foreach ($email_to as $email) {
            $header = 'MIME-Version: 1.0' . "\n" . 'Content-type: text/html; charset=UTF-8';
            if ($from_email)
                $header = $header."\n".'From: '.$name_from.' <'.$from_email.'> ';
            $result = mail($email, $subject, $message, $header);    
        }
        return $result;
    }
}
?>